/*
 * Cubem - Copyright (C) 2008 Ewan Davies
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */
package cubem;

import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import org.netbeans.microedition.lcdui.SplashScreen;

import rubiksjtimer.Scramble;
import rubiksjtimer.Scramble2x2x2;
import rubiksjtimer.Scramble3x3x3;
import rubiksjtimer.Scramble4x4x4;
import rubiksjtimer.Scramble5x5x5;
        
        
import rubiksjtimer.ScrambleClock;
import rubiksjtimer.ScrambleMegaminx;
import rubiksjtimer.ScramblePyraminx;
import rubiksjtimer.ScrambleSquare1;

/* Compilation defines for w.i.p features */
// # define AllowPopDNF
// # define SaveConfig
// # define SaveRecordTimes
// # define SaveSession
// # define Have6x6x6
// # define Have7x7x7

/**
 * @author Ewan
 */
public class CubemMIDlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;

//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
private java.util.Hashtable __previousDisplayables = new java.util.Hashtable ();
private Command exitCommand;
private Command helpCommand;
private Command backCommand;
private Command newScrambleCommand;
private Command okCommand;
private Command stopCommand;
private Command startCommand;
private Command settingsCommand;
private Command insertTimeCommand;
private Form scrambleForm;
private SplashScreen splashScreen;
private List menuList;
private Form helpForm;
private StringItem stringItem2;
private StringItem stringItem1;
private StringItem stringItem;
private List stoppedList;
private List settingsList;
private PllCanvas pllCanvas;
private SessionCanvas sessionCanvas;
private TextBox textBoxInsertTime;
private Image imgMiniTree;
private Image imgpll21;
private Image imgpll12;
private Image imgpll20;
private Image imgpll15;
private Image imgpll14;
private Image imgpll11;
private Image imgpll10;
private Image imgpll18;
private Image imgpll13;
private Image imgpll05;
private Image imgpll06;
private Image imgpll03;
private Image imgpll04;
private Image imgpll17;
private Image imgpll02;
private Image imgpll16;
private Image imgpll19;
private Image imgpll09;
private Image imgpll07;
private Image imgpll08;
private Image imgpll01;
private Image imageCubeLogo;
private Font font;
//</editor-fold>//GEN-END:|fields|0|

    /**
     * Variables
     */
    private static final String CONFIG_STORE = "cubemstore";
    private static final String RECORD_STORE = "cubemrecordstore";
    private static final String SESSION_STORE = "cubemsessionstore";
    private static final String APP_VERSION = "v0.2";
    Scramble    scrambler;
    Image[]     pllImages;
    String      currentScramble;
    Solve       currentSolve;
    
    /**
     * Config Settings
     */
    boolean     confPllShowName;
    boolean     confPllRealProbability;
    long        confPllWaitTime;
    
    /**
     * The CubemMIDlet constructor.
     */
    public CubemMIDlet() {
    }

    /**
     * 
     */
    private void newScramble() {
        currentScramble = scrambler.generateScramble();
        getScrambleForm().deleteAll();
        getScrambleForm().append(currentScramble);
    }
    
    /**
     * 
     */
    public String getScramble() {
        return currentScramble;
    }
    
    /**
     * 
     */
    private void updateSettingsList() {
        settingsList.set(0, "Show pll names: " + (confPllShowName ? "true" : "false"), null);
        settingsList.set(1, "Use real pll probabilities: " + (confPllRealProbability ? "true" : "false"), null);
        settingsList.set(2, "Pll wait time: " + Long.toString(confPllWaitTime), null);    
    }
    
    /**
     * 
     */
    public void updatePllCanvasCommands() {
        getPllCanvas().removeCommand (getExitCommand ());
        getPllCanvas().removeCommand (getSettingsCommand ());
        getPllCanvas().removeCommand (getStopCommand ());
        
        switch (getPllCanvas().getStatus()) {
            case TimerCanvas.STATUS_NOT_STARTED:
                getPllCanvas().addCommand (getExitCommand ());
                getPllCanvas().addCommand (getSettingsCommand ());
                break;
            case TimerCanvas.STATUS_RUNNING:
                getPllCanvas().addCommand (getStopCommand ());
                break;
            case TimerCanvas.STATUS_STOPPED:
                getPllCanvas().addCommand (getExitCommand ());
                getPllCanvas().addCommand (getSettingsCommand ());
                break;
        }
    }
    
    /**
     * 
     */
    public void updateSessionCanvasCommands() {
        getSessionCanvas().removeCommand (getExitCommand ());
        getSessionCanvas().removeCommand (getHelpCommand());
        getSessionCanvas().removeCommand (getStartCommand());
        getSessionCanvas().removeCommand (getStopCommand ());
        getSessionCanvas().removeCommand (getNewScrambleCommand ());
        getSessionCanvas().removeCommand (getInsertTimeCommand ());
        
        switch (getSessionCanvas().getStatus()) {
            case TimerCanvas.STATUS_NOT_STARTED:
                getSessionCanvas().addCommand (getNewScrambleCommand ());
                getSessionCanvas().addCommand (getExitCommand ());
                getSessionCanvas().addCommand (getHelpCommand());
                getSessionCanvas().addCommand (getStartCommand());
                getSessionCanvas().addCommand (getInsertTimeCommand ());
                break;
            case TimerCanvas.STATUS_RUNNING:
                getSessionCanvas().addCommand (getStopCommand ());
                break;
            case TimerCanvas.STATUS_STOPPED:
                
                break;
        }
    }
    
    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
    
     /**
     * Read configuration data from a settings store
     */
    protected void readRecordTimes() {
//#ifdef SaveRecordTimes
        RecordStore rs = null;
        /*
         * Read the settings from the recordstore
         * TODO: Implement
         */
        try {
            rs = RecordStore.openRecordStore(RECORD_STORE, false);
            
            byte[] rec = new byte[rs.getRecordSize(0)];
            rec = rs.getRecord(0);
            ByteArrayInputStream stream = new ByteArrayInputStream(rec);
            DataInputStream reader = new DataInputStream(stream);
                       
            confPllShowName = reader.readBoolean();
            confPllRealProbability = reader.readBoolean();
            confPllWaitTime = reader.readLong();
                        
        } catch (Exception e) {
            // if we can't read it then use the default
            confPllShowName = true;
            confPllRealProbability = false;
            confPllWaitTime = 1000;
        }
                
        /*
         * Finally close the store
         */
        try {
            rs.closeRecordStore();
        } catch (Exception e) {
        }
//#endif
    }
    
    /**
     * Read configuration data from a settings store
     */
    protected void readSettings() {
//#ifdef SaveConfig        
        RecordStore rs = null;
        /*
         * Read the settings from the recordstore
         */
        try {
            rs = RecordStore.openRecordStore(CONFIG_STORE, false);
            
            byte[] rec = new byte[rs.getRecordSize(0)];
            rec = rs.getRecord(0);
            ByteArrayInputStream stream = new ByteArrayInputStream(rec);
            DataInputStream reader = new DataInputStream(stream);
                       
            confPllShowName = reader.readBoolean();
            confPllRealProbability = reader.readBoolean();
            confPllWaitTime = reader.readLong();
                        
        } catch (Exception e) {
            // if we can't read it then use the default
            confPllShowName = true;
            confPllRealProbability = false;
            confPllWaitTime = 1000;
        }
                
        /*
         * Finally close the store
         */
        try {
            rs.closeRecordStore();
        } catch (Exception e) {
        }
//#endif        
    }

    /**
     * Write configuration data to a settings store
     */
    protected void writeSettings() {
//#ifdef SaveConfig        
        RecordStore rs = null;
        try {
            rs = RecordStore.openRecordStore(CONFIG_STORE, true);
        } catch (RecordStoreException rse) {
            // do nothing
            return;
        }

        /*
         * prepare settings as byte arrays
         */
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        DataOutputStream writer = new DataOutputStream(stream);
        try {
            writer.writeBoolean(confPllShowName);
            writer.writeBoolean(confPllRealProbability);
            writer.writeLong(confPllWaitTime);
            writer.flush();
        } catch (IOException e) {
            // pass
        } finally {
            byte[] rec = stream.toByteArray();
        
            try {
                rs.setRecord(0, rec, 0, rec.length);
                rs.closeRecordStore();
            } catch (InvalidRecordIDException iride) { 
                // so this record doesn't exist, write a new one
                try {
                    rs.addRecord(rec, 0, rec.length);
                    rs.closeRecordStore();
                } catch (Exception e) {
                    //writing failed
                }
            } catch (RecordStoreException rse) {
                //writing failed
            }
        }
//#endif        
    }
        
//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
/**
 * Switches a display to previous displayable of the current displayable.
 * The <code>display</code> instance is obtain from the <code>getDisplay</code> method.
 */
private void switchToPreviousDisplayable () {
Displayable __currentDisplayable = getDisplay ().getCurrent ();
if (__currentDisplayable != null) {
Displayable __nextDisplayable = (Displayable) __previousDisplayables.get (__currentDisplayable);
if (__nextDisplayable != null) {
switchDisplayable (null, __nextDisplayable);
}
}
}
//</editor-fold>//GEN-END:|methods|0|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
/**
 * Initilizes the application.
 * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
 */
private void initialize () {//GEN-END:|0-initialize|0|0-preInitialize
    /*
     * Read the settings
     */
    readSettings();

try {//GEN-BEGIN:|0-initialize|1|152-@java.io.IOException
imgpll21 = Image.createImage ("/pll21.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|1|152-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|2|153-@java.io.IOException
try {
imgpll12 = Image.createImage ("/pll12.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|2|153-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|3|154-@java.io.IOException
try {
imgpll20 = Image.createImage ("/pll20.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|3|154-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|4|155-@java.io.IOException
try {
imgpll15 = Image.createImage ("/pll15.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|4|155-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|5|156-@java.io.IOException
try {
imgpll14 = Image.createImage ("/pll14.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|5|156-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|6|157-@java.io.IOException
try {
imgpll11 = Image.createImage ("/pll11.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|6|157-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|7|158-@java.io.IOException
try {
imgpll10 = Image.createImage ("/pll10.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|7|158-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|8|159-@java.io.IOException
try {
imgpll18 = Image.createImage ("/pll18.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|8|159-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|9|151-@java.io.IOException
try {
imgpll13 = Image.createImage ("/pll13.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|9|151-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|10|171-@java.io.IOException
try {
imgpll05 = Image.createImage ("/pll05.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|10|171-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|11|170-@java.io.IOException
try {
imgpll06 = Image.createImage ("/pll06.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|11|170-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|12|169-@java.io.IOException
try {
imgpll03 = Image.createImage ("/pll03.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|12|169-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|13|168-@java.io.IOException
try {
imgpll04 = Image.createImage ("/pll04.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|13|168-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|14|163-@java.io.IOException
try {
imgpll17 = Image.createImage ("/pll17.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|14|163-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|15|162-@java.io.IOException
try {
imgpll02 = Image.createImage ("/pll02.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|15|162-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|16|161-@java.io.IOException
try {
imgpll16 = Image.createImage ("/pll16.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|16|161-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|17|160-@java.io.IOException
try {
imgpll19 = Image.createImage ("/pll19.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|17|160-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|18|167-@java.io.IOException
try {
imgpll09 = Image.createImage ("/pll09.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|18|167-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|19|166-@java.io.IOException
try {
imgpll07 = Image.createImage ("/pll07.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|19|166-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|20|165-@java.io.IOException
try {
imgpll08 = Image.createImage ("/pll08.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|20|165-@java.io.IOException
e.printStackTrace ();
}//GEN-BEGIN:|0-initialize|21|164-@java.io.IOException
try {
imgpll01 = Image.createImage ("/pll01.gif");
} catch (java.io.IOException e) {//GEN-END:|0-initialize|21|164-@java.io.IOException
e.printStackTrace ();
}//GEN-LINE:|0-initialize|22|0-postInitialize
    /** 
     * load pll images 
     */
    pllImages = new Image[21];
    pllImages[0] = imgpll01;
    pllImages[1] = imgpll02;
    pllImages[2] = imgpll03;
    pllImages[3] = imgpll04;
    pllImages[4] = imgpll05;
    pllImages[5] = imgpll06;
    pllImages[6] = imgpll07;
    pllImages[7] = imgpll08;
    pllImages[8] = imgpll09;
    pllImages[9] = imgpll10;
    pllImages[10] = imgpll11;
    pllImages[11] = imgpll12;
    pllImages[12] = imgpll13;
    pllImages[13] = imgpll14;
    pllImages[14] = imgpll15;
    pllImages[15] = imgpll16;
    pllImages[16] = imgpll17;
    pllImages[17] = imgpll18;
    pllImages[18] = imgpll19;
    pllImages[19] = imgpll20;
    pllImages[20] = imgpll21;    
}//GEN-BEGIN:|0-initialize|23|
//</editor-fold>//GEN-END:|0-initialize|23|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
/**
 * Performs an action assigned to the Mobile Device - MIDlet Started point.
 */
public void startMIDlet () {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
switchDisplayable (null, getSplashScreen ());//GEN-LINE:|3-startMIDlet|1|3-postAction
    // write post-action user code here
}//GEN-BEGIN:|3-startMIDlet|2|
//</editor-fold>//GEN-END:|3-startMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
/**
 * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
 */
public void resumeMIDlet () {//GEN-END:|4-resumeMIDlet|0|4-preAction
        getPllCanvas().reset();
        getSessionCanvas().reset();
        scrambler = null;
switchDisplayable (null, getMenuList ());//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
}//GEN-BEGIN:|4-resumeMIDlet|2|
//</editor-fold>//GEN-END:|4-resumeMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
/**
 * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
 * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
 * @param nextDisplayable the Displayable to be set
 */
public void switchDisplayable (Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
    if (nextDisplayable == getSettingsList())
        updateSettingsList();
Display display = getDisplay ();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
Displayable __currentDisplayable = display.getCurrent ();
if (__currentDisplayable != null  &&  nextDisplayable != null) {
__previousDisplayables.put (nextDisplayable, __currentDisplayable);
}
if (alert == null) {
display.setCurrent (nextDisplayable);
} else {
display.setCurrent (alert, nextDisplayable);
}//GEN-END:|5-switchDisplayable|1|5-postSwitch
    if (nextDisplayable == getPllCanvas()) {
        updatePllCanvasCommands();
        getPllCanvas().repaint();
    }
    else if (nextDisplayable == getSessionCanvas()) {
        updateSessionCanvasCommands();
        getSessionCanvas().repaint();
    }
}//GEN-BEGIN:|5-switchDisplayable|2|
//</editor-fold>//GEN-END:|5-switchDisplayable|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
/**
 * Returns an initiliazed instance of exitCommand component.
 * @return the initialized component instance
 */
public Command getExitCommand () {
if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
        // write pre-init user code here
exitCommand = new Command ("Exit", Command.EXIT, 5);//GEN-LINE:|18-getter|1|18-postInit
        // write post-init user code here
}//GEN-BEGIN:|18-getter|2|
return exitCommand;
}
//</editor-fold>//GEN-END:|18-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
/**
 * Called by a system to indicated that a command has been invoked on a particular displayable.
 * @param command the Command that was invoked
 * @param displayable the Displayable where the command was invoked
 */
public void commandAction (Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
if (displayable == helpForm) {//GEN-BEGIN:|7-commandAction|1|74-preAction
if (command == backCommand) {//GEN-END:|7-commandAction|1|74-preAction
                // write pre-action user code here
switchToPreviousDisplayable ();//GEN-LINE:|7-commandAction|2|74-postAction
                // write post-action user code here
}//GEN-BEGIN:|7-commandAction|3|27-preAction
} else if (displayable == menuList) {
if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|3|27-preAction
                // write pre-action user code here
menuListAction ();//GEN-LINE:|7-commandAction|4|27-postAction
                // write post-action user code here
} else if (command == exitCommand) {//GEN-LINE:|7-commandAction|5|37-preAction
                // write pre-action user code here
exitMIDlet ();//GEN-LINE:|7-commandAction|6|37-postAction
                // write post-action user code here
} else if (command == helpCommand) {//GEN-LINE:|7-commandAction|7|67-preAction
                // write pre-action user code here
switchDisplayable (null, getHelpForm ());//GEN-LINE:|7-commandAction|8|67-postAction
                // write post-action user code here
}//GEN-BEGIN:|7-commandAction|9|177-preAction
} else if (displayable == pllCanvas) {
if (command == exitCommand) {//GEN-END:|7-commandAction|9|177-preAction
 // write pre-action user code here
switchDisplayable (null, getMenuList ());//GEN-LINE:|7-commandAction|10|177-postAction
 getPllCanvas().reset();
} else if (command == settingsCommand) {//GEN-LINE:|7-commandAction|11|197-preAction
// write pre-action user code here
switchDisplayable (null, getSettingsList ());//GEN-LINE:|7-commandAction|12|197-postAction
 // write post-action user code here
} else if (command == stopCommand) {//GEN-LINE:|7-commandAction|13|206-preAction
 // write pre-action user code here
getPllCanvas().stopTimer();//GEN-LINE:|7-commandAction|14|206-postAction
 // write post-action user code here
}//GEN-BEGIN:|7-commandAction|15|86-preAction
} else if (displayable == scrambleForm) {
if (command == newScrambleCommand) {//GEN-END:|7-commandAction|15|86-preAction
                // write pre-action user code here
newScramble();//GEN-LINE:|7-commandAction|16|86-postAction
                // write post-action user code here
} else if (command == okCommand) {//GEN-LINE:|7-commandAction|17|89-preAction
                // write pre-action user code here
switchDisplayable (null, getSessionCanvas ());//GEN-LINE:|7-commandAction|18|89-postAction
                // write post-action user code here
}//GEN-BEGIN:|7-commandAction|19|213-preAction
} else if (displayable == sessionCanvas) {
if (command == exitCommand) {//GEN-END:|7-commandAction|19|213-preAction
 // write pre-action user code here
    getSessionCanvas().session.writeSession(SESSION_STORE);
switchDisplayable (null, getMenuList ());//GEN-LINE:|7-commandAction|20|213-postAction
 getSessionCanvas().reset();
} else if (command == helpCommand) {//GEN-LINE:|7-commandAction|21|247-preAction
 // write pre-action user code here
switchDisplayable (null, getHelpForm ());//GEN-LINE:|7-commandAction|22|247-postAction
 // write post-action user code here
} else if (command == insertTimeCommand) {//GEN-LINE:|7-commandAction|23|252-preAction
 // write pre-action user code here
switchDisplayable (null, getTextBoxInsertTime ());//GEN-LINE:|7-commandAction|24|252-postAction
 // write post-action user code here
} else if (command == newScrambleCommand) {//GEN-LINE:|7-commandAction|25|249-preAction
 // write pre-action user code here
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|7-commandAction|26|249-postAction
 // write post-action user code here
} else if (command == startCommand) {//GEN-LINE:|7-commandAction|27|214-preAction
 // write pre-action user code here
getSessionCanvas().startTimer();//GEN-LINE:|7-commandAction|28|214-postAction
 
} else if (command == stopCommand) {//GEN-LINE:|7-commandAction|29|215-preAction
 getSessionCanvas().stopTimer();
 getStoppedList().setTitle(getSessionCanvas().getStoppedTime());
switchDisplayable (null, getStoppedList ());//GEN-LINE:|7-commandAction|30|215-postAction

}//GEN-BEGIN:|7-commandAction|31|187-preAction
} else if (displayable == settingsList) {
if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|31|187-preAction
 // write pre-action user code here
settingsListAction ();//GEN-LINE:|7-commandAction|32|187-postAction
 // write post-action user code here
} else if (command == backCommand) {//GEN-LINE:|7-commandAction|33|202-preAction
 // write pre-action user code here
switchToPreviousDisplayable ();//GEN-LINE:|7-commandAction|34|202-postAction
 // write post-action user code here
}//GEN-BEGIN:|7-commandAction|35|23-preAction
} else if (displayable == splashScreen) {
if (command == SplashScreen.DISMISS_COMMAND) {//GEN-END:|7-commandAction|35|23-preAction
                // write pre-action user code here
switchDisplayable (null, getMenuList ());//GEN-LINE:|7-commandAction|36|23-postAction
                // write post-action user code here
}//GEN-BEGIN:|7-commandAction|37|119-preAction
} else if (displayable == stoppedList) {
if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|37|119-preAction
 // write pre-action user code here
stoppedListAction ();//GEN-LINE:|7-commandAction|38|119-postAction
 // write post-action user code here
}//GEN-BEGIN:|7-commandAction|39|242-preAction
} else if (displayable == textBoxInsertTime) {
if (command == backCommand) {//GEN-END:|7-commandAction|39|242-preAction
 // write pre-action user code here
switchDisplayable (null, getTextBoxInsertTime ());//GEN-LINE:|7-commandAction|40|242-postAction
 // write post-action user code here
} else if (command == okCommand) {//GEN-LINE:|7-commandAction|41|241-preAction
 // write pre-action user code here
    // Parse the input and work out a time
    String input = getTextBoxInsertTime().getString();
    if (input.toUpperCase().equals("DNF")) {
        getSessionCanvas().session.addTime(getScramble(), 0, Solve.PEN_DNF);
    }
    else {
        try {
            int colonIdx = input.indexOf(':', 0);
            int pointIdx = input.indexOf('.', colonIdx);
            int mins = 0, secs = 0, hundreths = 0;
            boolean failed = false;
            if (pointIdx < 0) {
                failed = true;
                pointIdx = 0;
            }
            
            String s1, s2, s3;
            // s1 is assigned after asserting colonIdx >= 0
            s2 = input.substring(colonIdx + 1, pointIdx);
            s3 = input.substring(pointIdx + 1);
            /* s3 is hundreths so pad/trim it to xx */
            while (s3.length() < 2) {
                s3 += '0';
            }
            if (s3.length() > 2) {
                failed = true;
            }
            
            if (colonIdx < 0) {
                // No colon so assume its xx.xx in seconds
                mins = 0;
                secs = Integer.parseInt(s2);
                hundreths = Integer.parseInt(s3);
            }
            else {
                // assume mm:ss.xx
                s1 = input.substring(0, colonIdx);
                mins = Integer.parseInt(s1);
                if (s2.length() != 2)
                    failed = true;
                secs = Integer.parseInt(s2);
                hundreths = Integer.parseInt(s3);
            }
            
            /* abandon if failed */
            if (failed)
                throw new NumberFormatException();
            
            long time = mins*60*1000 + secs*1000 + hundreths*10;
            getSessionCanvas().session.addTime(getScramble(), time, Solve.PEN_NONE);
        }
        catch (Exception e) {
            // parsing failed
            getTextBoxInsertTime().setString("Time regognition failed\nEnter mm:ss.hh or sss.hh to store a time,\nor type DNF");
            return;
        }
    }
switchDisplayable (null, getSessionCanvas ());//GEN-LINE:|7-commandAction|42|241-postAction
 // write post-action user code here
}//GEN-BEGIN:|7-commandAction|43|7-postCommandAction
}//GEN-END:|7-commandAction|43|7-postCommandAction
    // write post-action user code here
}//GEN-BEGIN:|7-commandAction|44|
//</editor-fold>//GEN-END:|7-commandAction|44|


//<editor-fold defaultstate="collapsed" desc=" Generated Getter: scrambleForm ">//GEN-BEGIN:|14-getter|0|14-preInit
/**
 * Returns an initiliazed instance of scrambleForm component.
 * @return the initialized component instance
 */
public Form getScrambleForm () {
if (scrambleForm == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
scrambleForm = new Form ("", new Item[] { });//GEN-BEGIN:|14-getter|1|14-postInit
scrambleForm.addCommand (getNewScrambleCommand ());
scrambleForm.addCommand (getOkCommand ());
scrambleForm.setCommandListener (this);//GEN-END:|14-getter|1|14-postInit
            newScramble();
}//GEN-BEGIN:|14-getter|2|
return scrambleForm;
}
//</editor-fold>//GEN-END:|14-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: splashScreen ">//GEN-BEGIN:|21-getter|0|21-preInit
/**
 * Returns an initiliazed instance of splashScreen component.
 * @return the initialized component instance
 */
public SplashScreen getSplashScreen () {
if (splashScreen == null) {//GEN-END:|21-getter|0|21-preInit
            // write pre-init user code here
splashScreen = new SplashScreen (getDisplay ());//GEN-BEGIN:|21-getter|1|21-postInit
splashScreen.setTitle ("Ewan Davies Presents:");
splashScreen.setCommandListener (this);
splashScreen.setImage (getImageCubeLogo ());
splashScreen.setText ("Cubem " + APP_VERSION);
splashScreen.setTimeout (2500);//GEN-END:|21-getter|1|21-postInit
            // write post-init user code here
}//GEN-BEGIN:|21-getter|2|
return splashScreen;
}
//</editor-fold>//GEN-END:|21-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: menuList ">//GEN-BEGIN:|25-getter|0|25-preInit
/**
 * Returns an initiliazed instance of menuList component.
 * @return the initialized component instance
 */
public List getMenuList () {
if (menuList == null) {//GEN-END:|25-getter|0|25-preInit
            // write pre-init user code here
menuList = new List ("Choose a Puzzle", Choice.IMPLICIT);//GEN-BEGIN:|25-getter|1|25-postInit
menuList.append ("2x2x2", null);
menuList.append ("3x3x3", null);
menuList.append ("4x4x4", null);
menuList.append ("5x5x5", null);
menuList.append ("6x6x6", null);
menuList.append ("7x7x7", null);
menuList.append ("Pyraminx", null);
menuList.append ("Megaminx", null);
menuList.append ("Square-1", null);
menuList.append ("Clock", null);
menuList.append ("PLL Trainer", null);
menuList.append ("Load Last Session", null);
menuList.addCommand (getExitCommand ());
menuList.addCommand (getHelpCommand ());
menuList.setCommandListener (this);
menuList.setFitPolicy (Choice.TEXT_WRAP_DEFAULT);
menuList.setSelectedFlags (new boolean[] { false, true, false, false, false, false, false, false, false, false, false, false });//GEN-END:|25-getter|1|25-postInit
            // write post-init user code here
}//GEN-BEGIN:|25-getter|2|
return menuList;
}
//</editor-fold>//GEN-END:|25-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: menuListAction ">//GEN-BEGIN:|25-action|0|25-preAction
/**
 * Performs an action assigned to the selected list element in the menuList component.
 */
public void menuListAction () {//GEN-END:|25-action|0|25-preAction
        // enter pre-action user code here
switch (getMenuList ().getSelectedIndex ()) {//GEN-BEGIN:|25-action|1|29-preAction
case 0://GEN-END:|25-action|1|29-preAction
                scrambler = new Scramble2x2x2();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|2|29-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|3|30-preAction
case 1://GEN-END:|25-action|3|30-preAction
                scrambler = new Scramble3x3x3();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|4|30-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|5|31-preAction
case 2://GEN-END:|25-action|5|31-preAction
                scrambler = new Scramble4x4x4();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|6|31-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|7|32-preAction
case 3://GEN-END:|25-action|7|32-preAction
                scrambler = new Scramble5x5x5();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|8|32-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|9|59-preAction
case 4://GEN-END:|25-action|9|59-preAction
                //scrambler = new Scramble6x6x6();
                //getSessionCanvas().newSession(scrambler.getName());
                //getScrambleForm().setTitle(scrambler.getName());
                //newScramble();
//GEN-LINE:|25-action|10|59-postAction
                // write post-action user code here
                //temporary:
break;//GEN-BEGIN:|25-action|11|60-preAction
case 5://GEN-END:|25-action|11|60-preAction
                //scrambler = new Scramble7x7x7();
                //getSessionCanvas().newSession(scrambler.getName());
                //getScrambleForm().setTitle(scrambler.getName());
                //newScramble();
//GEN-LINE:|25-action|12|60-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|13|61-preAction
case 6://GEN-END:|25-action|13|61-preAction
                scrambler = new ScramblePyraminx();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|14|61-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|15|62-preAction
case 7://GEN-END:|25-action|15|62-preAction
                scrambler = new ScrambleMegaminx();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|16|62-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|17|82-preAction
case 8://GEN-END:|25-action|17|82-preAction
                scrambler = new ScrambleSquare1();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|18|82-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|19|65-preAction
case 9://GEN-END:|25-action|19|65-preAction
                scrambler = new ScrambleClock();
                getSessionCanvas().newSession(scrambler.getName());
                getScrambleForm().setTitle(scrambler.getName());
                newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|25-action|20|65-postAction
                // write post-action user code here
break;//GEN-BEGIN:|25-action|21|145-preAction
case 10://GEN-END:|25-action|21|145-preAction

switchDisplayable (null, getPllCanvas ());//GEN-LINE:|25-action|22|145-postAction

break;//GEN-BEGIN:|25-action|23|237-preAction
case 11://GEN-END:|25-action|23|237-preAction
 // write pre-action user code here
    getSessionCanvas().session = Session.readSession(SESSION_STORE, 0);
    if (getSessionCanvas().session == null)
        return;
    if (getSessionCanvas().session.getName().equals("2x2x2"))
        scrambler = new Scramble2x2x2();
    else if (getSessionCanvas().session.getName().equals("3x3x3"))
        scrambler = new Scramble3x3x3();
    else if (getSessionCanvas().session.getName().equals("4x4x4"))
        scrambler = new Scramble4x4x4();
    else if (getSessionCanvas().session.getName().equals("5x5x5"))
        scrambler = new Scramble5x5x5();
    else if (getSessionCanvas().session.getName().equals("6x6x6"))
        scrambler = new Scramble3x3x3(); // TODO 6x6x6 fix
    else if (getSessionCanvas().session.getName().equals("7x7x7)"))
        scrambler = new Scramble3x3x3(); // TODO 7x7x7 fix
    else if (getSessionCanvas().session.getName().equals("Pyraminx"))
        scrambler = new ScramblePyraminx();
    else if (getSessionCanvas().session.getName().equals("Megaminx"))
        scrambler = new ScrambleMegaminx();
    else if (getSessionCanvas().session.getName().equals("Square-1"))
        scrambler = new ScrambleSquare1();
    else if (getSessionCanvas().session.getName().equals("Clock)"))
        scrambler = new ScrambleClock();
    else if (getSessionCanvas().session.getName().equals("3x3x3"))
        scrambler = new Scramble3x3x3();
    
    getScrambleForm().setTitle(scrambler.getName());
switchDisplayable (null, getSessionCanvas ());//GEN-LINE:|25-action|24|237-postAction
 // write post-action user code here
break;//GEN-BEGIN:|25-action|25|25-postAction
}//GEN-END:|25-action|25|25-postAction
        // enter post-action user code here
}//GEN-BEGIN:|25-action|26|
//</editor-fold>//GEN-END:|25-action|26|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: imgMiniTree ">//GEN-BEGIN:|36-getter|0|36-preInit
/**
 * Returns an initiliazed instance of imgMiniTree component.
 * @return the initialized component instance
 */
public Image getImgMiniTree () {
if (imgMiniTree == null) {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
try {//GEN-BEGIN:|36-getter|1|36-@java.io.IOException
imgMiniTree = Image.createImage ("/mini tree.jpg");
} catch (java.io.IOException e) {//GEN-END:|36-getter|1|36-@java.io.IOException
                e.printStackTrace();
}//GEN-LINE:|36-getter|2|36-postInit
            // write post-init user code here
}//GEN-BEGIN:|36-getter|3|
return imgMiniTree;
}
//</editor-fold>//GEN-END:|36-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: helpCommand ">//GEN-BEGIN:|66-getter|0|66-preInit
/**
 * Returns an initiliazed instance of helpCommand component.
 * @return the initialized component instance
 */
public Command getHelpCommand () {
if (helpCommand == null) {//GEN-END:|66-getter|0|66-preInit
            // write pre-init user code here
helpCommand = new Command ("Help", Command.HELP, 5);//GEN-LINE:|66-getter|1|66-postInit
            // write post-init user code here
}//GEN-BEGIN:|66-getter|2|
return helpCommand;
}
//</editor-fold>//GEN-END:|66-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|73-getter|0|73-preInit
/**
 * Returns an initiliazed instance of backCommand component.
 * @return the initialized component instance
 */
public Command getBackCommand () {
if (backCommand == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
backCommand = new Command ("Back", Command.BACK, 3);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here
}//GEN-BEGIN:|73-getter|2|
return backCommand;
}
//</editor-fold>//GEN-END:|73-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: helpForm ">//GEN-BEGIN:|72-getter|0|72-preInit
/**
 * Returns an initiliazed instance of helpForm component.
 * @return the initialized component instance
 */
public Form getHelpForm () {
if (helpForm == null) {//GEN-END:|72-getter|0|72-preInit
            // write pre-init user code here
helpForm = new Form ("Help", new Item[] { getStringItem (), getStringItem1 (), getStringItem2 () });//GEN-BEGIN:|72-getter|1|72-postInit
helpForm.addCommand (getBackCommand ());
helpForm.setCommandListener (this);//GEN-END:|72-getter|1|72-postInit
            // write post-init user code here
}//GEN-BEGIN:|72-getter|2|
return helpForm;
}
//</editor-fold>//GEN-END:|72-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: newScrambleCommand ">//GEN-BEGIN:|85-getter|0|85-preInit
/**
 * Returns an initiliazed instance of newScrambleCommand component.
 * @return the initialized component instance
 */
public Command getNewScrambleCommand () {
if (newScrambleCommand == null) {//GEN-END:|85-getter|0|85-preInit
            // write pre-init user code here
newScrambleCommand = new Command ("New", "Scramble", Command.SCREEN, 3);//GEN-LINE:|85-getter|1|85-postInit
            // write post-init user code here
}//GEN-BEGIN:|85-getter|2|
return newScrambleCommand;
}
//</editor-fold>//GEN-END:|85-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|88-getter|0|88-preInit
/**
 * Returns an initiliazed instance of okCommand component.
 * @return the initialized component instance
 */
public Command getOkCommand () {
if (okCommand == null) {//GEN-END:|88-getter|0|88-preInit
            // write pre-init user code here
okCommand = new Command ("Ok", Command.OK, 0);//GEN-LINE:|88-getter|1|88-postInit
            // write post-init user code here
}//GEN-BEGIN:|88-getter|2|
return okCommand;
}
//</editor-fold>//GEN-END:|88-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: startCommand ">//GEN-BEGIN:|104-getter|0|104-preInit
/**
 * Returns an initiliazed instance of startCommand component.
 * @return the initialized component instance
 */
public Command getStartCommand () {
if (startCommand == null) {//GEN-END:|104-getter|0|104-preInit
 // write pre-init user code here
startCommand = new Command ("Start", Command.SCREEN, 0);//GEN-LINE:|104-getter|1|104-postInit
 // write post-init user code here
}//GEN-BEGIN:|104-getter|2|
return startCommand;
}
//</editor-fold>//GEN-END:|104-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stopCommand ">//GEN-BEGIN:|108-getter|0|108-preInit
/**
 * Returns an initiliazed instance of stopCommand component.
 * @return the initialized component instance
 */
public Command getStopCommand () {
if (stopCommand == null) {//GEN-END:|108-getter|0|108-preInit
 // write pre-init user code here
stopCommand = new Command ("Stop", Command.STOP, 0);//GEN-LINE:|108-getter|1|108-postInit
 // write post-init user code here
}//GEN-BEGIN:|108-getter|2|
return stopCommand;
}
//</editor-fold>//GEN-END:|108-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stoppedList ">//GEN-BEGIN:|118-getter|0|118-preInit
/**
 * Returns an initiliazed instance of stoppedList component.
 * @return the initialized component instance
 */
public List getStoppedList () {
if (stoppedList == null) {//GEN-END:|118-getter|0|118-preInit
 // write pre-init user code here
stoppedList = new List ("stoppedList", Choice.IMPLICIT);//GEN-BEGIN:|118-getter|1|118-postInit
stoppedList.append ("Accept", null);
stoppedList.append ("DNF", null);
stoppedList.append ("Penalty +2", null);
stoppedList.append ("Resume", null);
stoppedList.append ("Reject", null);
stoppedList.setCommandListener (this);
stoppedList.setFitPolicy (Choice.TEXT_WRAP_DEFAULT);
stoppedList.setSelectedFlags (new boolean[] { true, false, false, false, false });//GEN-END:|118-getter|1|118-postInit
 // write post-init user code here
}//GEN-BEGIN:|118-getter|2|
return stoppedList;
}
//</editor-fold>//GEN-END:|118-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: stoppedListAction ">//GEN-BEGIN:|118-action|0|118-preAction
/**
 * Performs an action assigned to the selected list element in the stoppedList component.
 */
public void stoppedListAction () {//GEN-END:|118-action|0|118-preAction
 // enter pre-action user code here
switch (getStoppedList ().getSelectedIndex ()) {//GEN-BEGIN:|118-action|1|121-preAction
case 0://GEN-END:|118-action|1|121-preAction
getSessionCanvas().storeTime(Solve.PEN_NONE);
newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|118-action|2|121-postAction

break;//GEN-BEGIN:|118-action|3|123-preAction
case 1://GEN-END:|118-action|3|123-preAction
getSessionCanvas().storeTime(Solve.PEN_DNF);
newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|118-action|4|123-postAction
 // write post-action user code here
break;//GEN-BEGIN:|118-action|5|124-preAction
case 2://GEN-END:|118-action|5|124-preAction
getSessionCanvas().storeTime(Solve.PEN_FOUL);
newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|118-action|6|124-postAction
 // write post-action user code here
break;//GEN-BEGIN:|118-action|7|125-preAction
case 3://GEN-END:|118-action|7|125-preAction
 // write pre-action user code here
//GEN-LINE:|118-action|8|125-postAction
 // write post-action user code here
break;//GEN-BEGIN:|118-action|9|126-preAction
case 4://GEN-END:|118-action|9|126-preAction
 getSessionCanvas().rejectTime();
 newScramble();
switchDisplayable (null, getScrambleForm ());//GEN-LINE:|118-action|10|126-postAction

break;//GEN-BEGIN:|118-action|11|118-postAction
}//GEN-END:|118-action|11|118-postAction
 // enter post-action user code here
getStoppedList().setSelectedIndex(0, true);
}//GEN-BEGIN:|118-action|12|
//</editor-fold>//GEN-END:|118-action|12|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: settingsCommand ">//GEN-BEGIN:|135-getter|0|135-preInit
/**
 * Returns an initiliazed instance of settingsCommand component.
 * @return the initialized component instance
 */
public Command getSettingsCommand () {
if (settingsCommand == null) {//GEN-END:|135-getter|0|135-preInit
 // write pre-init user code here
settingsCommand = new Command ("Settings", Command.SCREEN, 3);//GEN-LINE:|135-getter|1|135-postInit
 // write post-init user code here
}//GEN-BEGIN:|135-getter|2|
return settingsCommand;
}
//</editor-fold>//GEN-END:|135-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: pllCanvas ">//GEN-BEGIN:|176-getter|0|176-preInit
/**
 * Returns an initiliazed instance of pllCanvas component.
 * @return the initialized component instance
 */
public PllCanvas getPllCanvas () {
if (pllCanvas == null) {//GEN-END:|176-getter|0|176-preInit
 // write pre-init user code here
pllCanvas = new PllCanvas ();//GEN-BEGIN:|176-getter|1|176-postInit
pllCanvas.setTitle ("PLL Trainer");
pllCanvas.addCommand (getExitCommand ());
pllCanvas.addCommand (getSettingsCommand ());
pllCanvas.addCommand (getStopCommand ());
pllCanvas.setCommandListener (this);//GEN-END:|176-getter|1|176-postInit
updatePllCanvasCommands();
pllCanvas.setParent(this);
}//GEN-BEGIN:|176-getter|2|
return pllCanvas;
}
//</editor-fold>//GEN-END:|176-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: settingsList ">//GEN-BEGIN:|186-getter|0|186-preInit
/**
 * Returns an initiliazed instance of settingsList component.
 * @return the initialized component instance
 */
public List getSettingsList () {
if (settingsList == null) {//GEN-END:|186-getter|0|186-preInit
 // write pre-init user code here
settingsList = new List ("Settings", Choice.IMPLICIT);//GEN-BEGIN:|186-getter|1|186-postInit
settingsList.append ("Show pll names: " + (confPllShowName ? "true" : "false")
, null);
settingsList.append ("Use real pll probabilities: " + (confPllRealProbability ? "true" : "false"), null);
settingsList.append ("Pll wait time: " + Long.toString(confPllWaitTime), null);
settingsList.addCommand (getBackCommand ());
settingsList.setCommandListener (this);
settingsList.setFitPolicy (Choice.TEXT_WRAP_ON);
settingsList.setSelectedFlags (new boolean[] { false, false, false });//GEN-END:|186-getter|1|186-postInit

}//GEN-BEGIN:|186-getter|2|
return settingsList;
}
//</editor-fold>//GEN-END:|186-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: settingsListAction ">//GEN-BEGIN:|186-action|0|186-preAction
/**
 * Performs an action assigned to the selected list element in the settingsList component.
 */
public void settingsListAction () {//GEN-END:|186-action|0|186-preAction
 // enter pre-action user code here
String __selectedString = getSettingsList ().getString (getSettingsList ().getSelectedIndex ());//GEN-BEGIN:|186-action|1|189-preAction
if (__selectedString != null) {
if (__selectedString.equals ("Show pll names: " + (confPllShowName ? "true" : "false")
)) {//GEN-END:|186-action|1|189-preAction
 // write pre-action user code here
confPllShowName = !confPllShowName;//GEN-LINE:|186-action|2|189-postAction
 updateSettingsList();
} else if (__selectedString.equals ("Use real pll probabilities: " + (confPllRealProbability ? "true" : "false"))) {//GEN-LINE:|186-action|3|190-preAction
 
confPllRealProbability = !confPllRealProbability;//GEN-LINE:|186-action|4|190-postAction
 updateSettingsList();
} else if (__selectedString.equals ("Pll wait time: " + Long.toString(confPllWaitTime))) {//GEN-LINE:|186-action|5|191-preAction
 if (confPllWaitTime < 3000)
     confPllWaitTime += 200;
 else 
     confPllWaitTime = 200;
//GEN-LINE:|186-action|6|191-postAction
 updateSettingsList();
}//GEN-BEGIN:|186-action|7|186-postAction
}//GEN-END:|186-action|7|186-postAction
 // enter post-action user code here
}//GEN-BEGIN:|186-action|8|
//</editor-fold>//GEN-END:|186-action|8|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: sessionCanvas ">//GEN-BEGIN:|209-getter|0|209-preInit
/**
 * Returns an initiliazed instance of sessionCanvas component.
 * @return the initialized component instance
 */
public SessionCanvas getSessionCanvas () {
if (sessionCanvas == null) {//GEN-END:|209-getter|0|209-preInit
 // write pre-init user code here
sessionCanvas = new SessionCanvas ();//GEN-BEGIN:|209-getter|1|209-postInit
sessionCanvas.setTitle ("Cubem Timer");
sessionCanvas.addCommand (getExitCommand ());
sessionCanvas.addCommand (getStartCommand ());
sessionCanvas.addCommand (getStopCommand ());
sessionCanvas.addCommand (getHelpCommand ());
sessionCanvas.addCommand (getNewScrambleCommand ());
sessionCanvas.addCommand (getInsertTimeCommand ());
sessionCanvas.setCommandListener (this);//GEN-END:|209-getter|1|209-postInit
sessionCanvas.setParent(this);
updateSessionCanvasCommands();
}//GEN-BEGIN:|209-getter|2|
return sessionCanvas;
}
//</editor-fold>//GEN-END:|209-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|224-getter|0|224-preInit
/**
 * Returns an initiliazed instance of stringItem component.
 * @return the initialized component instance
 */
public StringItem getStringItem () {
if (stringItem == null) {//GEN-END:|224-getter|0|224-preInit
 // write pre-init user code here
stringItem = new StringItem ("Menu:", "Choose a puzzle to generate a scramble. Then press Ok to show the timer.");//GEN-BEGIN:|224-getter|1|224-postInit
stringItem.setLayout (ImageItem.LAYOUT_DEFAULT);
stringItem.setFont (getFont ());//GEN-END:|224-getter|1|224-postInit
 // write post-init user code here
}//GEN-BEGIN:|224-getter|2|
return stringItem;
}
//</editor-fold>//GEN-END:|224-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GEN-BEGIN:|225-getter|0|225-preInit
/**
 * Returns an initiliazed instance of stringItem1 component.
 * @return the initialized component instance
 */
public StringItem getStringItem1 () {
if (stringItem1 == null) {//GEN-END:|225-getter|0|225-preInit
 // write pre-init user code here
stringItem1 = new StringItem ("Timer:", "Use the star, hash or fire keys to start/stop the timer.", Item.PLAIN);//GEN-BEGIN:|225-getter|1|225-postInit
stringItem1.setFont (getFont ());//GEN-END:|225-getter|1|225-postInit
 // write post-init user code here
}//GEN-BEGIN:|225-getter|2|
return stringItem1;
}
//</editor-fold>//GEN-END:|225-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 ">//GEN-BEGIN:|227-getter|0|227-preInit
/**
 * Returns an initiliazed instance of stringItem2 component.
 * @return the initialized component instance
 */
public StringItem getStringItem2 () {
if (stringItem2 == null) {//GEN-END:|227-getter|0|227-preInit
 // write pre-init user code here
stringItem2 = new StringItem ("PLL Trainer:", "Use the star, hash or fire keys to continue. After the wait period a random PLL image will appear. Time yourself doing the algorithm.", Item.PLAIN);//GEN-BEGIN:|227-getter|1|227-postInit
stringItem2.setFont (getFont ());//GEN-END:|227-getter|1|227-postInit
 // write post-init user code here
}//GEN-BEGIN:|227-getter|2|
return stringItem2;
}
//</editor-fold>//GEN-END:|227-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: font ">//GEN-BEGIN:|226-getter|0|226-preInit
/**
 * Returns an initiliazed instance of font component.
 * @return the initialized component instance
 */
public Font getFont () {
if (font == null) {//GEN-END:|226-getter|0|226-preInit
 // write pre-init user code here
font = Font.getFont (Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);//GEN-LINE:|226-getter|1|226-postInit
 // write post-init user code here
}//GEN-BEGIN:|226-getter|2|
return font;
}
//</editor-fold>//GEN-END:|226-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageCubeLogo ">//GEN-BEGIN:|239-getter|0|239-preInit
/**
 * Returns an initiliazed instance of imageCubeLogo component.
 * @return the initialized component instance
 */
public Image getImageCubeLogo () {
if (imageCubeLogo == null) {//GEN-END:|239-getter|0|239-preInit
 // write pre-init user code here
try {//GEN-BEGIN:|239-getter|1|239-@java.io.IOException
imageCubeLogo = Image.createImage ("/cubelogo.jpg");
} catch (java.io.IOException e) {//GEN-END:|239-getter|1|239-@java.io.IOException
e.printStackTrace ();
}//GEN-LINE:|239-getter|2|239-postInit
 // write post-init user code here
}//GEN-BEGIN:|239-getter|3|
return imageCubeLogo;
}
//</editor-fold>//GEN-END:|239-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textBoxInsertTime ">//GEN-BEGIN:|240-getter|0|240-preInit
/**
 * Returns an initiliazed instance of textBoxInsertTime component.
 * @return the initialized component instance
 */
public TextBox getTextBoxInsertTime () {
if (textBoxInsertTime == null) {//GEN-END:|240-getter|0|240-preInit
 // write pre-init user code here
textBoxInsertTime = new TextBox ("Enter your time", "00:00.00", 100, TextField.ANY | TextField.NON_PREDICTIVE);//GEN-BEGIN:|240-getter|1|240-postInit
textBoxInsertTime.addCommand (getOkCommand ());
textBoxInsertTime.addCommand (getBackCommand ());
textBoxInsertTime.setCommandListener (this);
textBoxInsertTime.setInitialInputMode ("UCB_BASIC_LATIN");//GEN-END:|240-getter|1|240-postInit
 // write post-init user code here
}//GEN-BEGIN:|240-getter|2|
return textBoxInsertTime;
}
//</editor-fold>//GEN-END:|240-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: insertTimeCommand ">//GEN-BEGIN:|251-getter|0|251-preInit
/**
 * Returns an initiliazed instance of insertTimeCommand component.
 * @return the initialized component instance
 */
public Command getInsertTimeCommand () {
if (insertTimeCommand == null) {//GEN-END:|251-getter|0|251-preInit
 // write pre-init user code here
insertTimeCommand = new Command ("Add Time", Command.SCREEN, 3);//GEN-LINE:|251-getter|1|251-postInit
 // write post-init user code here
}//GEN-BEGIN:|251-getter|2|
return insertTimeCommand;
}
//</editor-fold>//GEN-END:|251-getter|2|

}